/**
 * 
 */
package org.braketester.view;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTabbedPane;

import org.braketester.entry.listeners.AddMeasurmentMenuItemListener;
import org.braketester.entry.listeners.ExitListener;
import org.braketester.entry.listeners.PropertiesMenuItemListener;
import org.braketester.model.RawData;

/**
 * @author LAP
 *
 */
public class MainFrame extends JFrame {
	private JMenuBar mainMenu;
	private JMenu file;
	private JMenuItem exit;
	private JMenuItem properties;
	private JMenuItem addMeasurment;
	private JTabbedPane tabbedContent;
	private static final long serialVersionUID = 1L;
	
	public MainFrame() {
		super("Title");
		createGUI();
	}
	
	private void createGUI() {
		createMenu();
		createContent();
		pack();
		setVisible(true);
	}
	
	private void createMenu() {
		mainMenu = new JMenuBar();
		createFileMenu();
		mainMenu.add(file);
		setJMenuBar(mainMenu);
	}
	
	private void createFileMenu() {
		file = new JMenu("File");
		properties = new JMenuItem("Properties");
		properties.addActionListener(new PropertiesMenuItemListener());
		file.add(properties);
		addMeasurment = new JMenuItem("Add measurment");
		addMeasurment.addActionListener(new AddMeasurmentMenuItemListener());
		file.add(addMeasurment);
		file.addSeparator();
		exit = new JMenuItem("Close");
		exit.addActionListener(new ExitListener());
		file.add(exit);
	}
	
	private void createContent() {
		tabbedContent = new JTabbedPane();
		setContentPane(tabbedContent);
	}
	
	public ChartView addMeasurement(RawData rawData) {
		ChartView view = new ChartView();
		tabbedContent.addTab(rawData.getName(), view);
		return view;
	}
}
